const axios = require('axios');

function createHeader() {
    const header = {
        'accept': 'application/json, text/plain, */*',
        'accept-language': 'zh-CN,zh;q=0.9',
        // 'accept-Encoding': 'gzip, deflate, br, zstd',响应加密方式
        'origin': 'https://telegram.blum.codes',
        'priority': 'u=1, i',
        'referer': 'https://telegram.blum.codes',
        'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
    }
    return header
}


function createAxios(proxy, headers) {
    const axiosInstance = axios.create({
        proxy: proxy,
        headers: headers,
        timeout: 1000 * 30
    });
    return axiosInstance

}


function parseProxy(proxyStr) {
    if (proxyStr == null || proxyStr.length == 0) {
        return null
    }
    let proxy = {
        protocol: "http",
    }
    proxyArr = proxyStr.split(":")
    if (proxyArr.length >= 2) {
        proxy.host = proxyArr[0]
        proxy.port = proxyArr[1]
    } else {
        return null
    }
    if (proxyArr.length >= 4) {
        proxy.auth = {
            username: proxyArr[2],
            password: proxyArr[3],
        }
    }
    return proxy
}

module.exports = {
    createHeader,
    createAxios,
    parseProxy,
}